package com.example.zyfypt_121azp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.zyfypt_121azp.R;
import com.example.zyfypt_121azp.bean.LoginBean;
import com.example.zyfypt_121azp.iface.LoginListener;
import com.example.zyfypt_121azp.model.LoginModel;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn,btn1;
    private EditText et1,et2;
    private LoginListener loginListener = new LoginListener() {
        @Override
        public void onResponse(LoginBean loginBean) {
            System.out.println("result:"+loginBean.getId());
            if(loginBean.getId()!=null) {
                Intent intent1 = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent1);
            }
        }

        @Override
        public void onFail(String msg) {
            System.out.println("fail");
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        Toast.makeText(this,"登录",Toast.LENGTH_SHORT).show();
        init();
    }

    private void init() {
        btn=(Button)findViewById(R.id.button);
        btn1=(Button)findViewById(R.id.button2);
        et1=(EditText) findViewById(R.id.editText7);
        et2=(EditText) findViewById(R.id.editText8);
        btn.setOnClickListener(this);
        btn1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button:
                System.out.println("点击登陆按钮");
                LoginModel loginModel = new LoginModel();
                loginModel.getResult(et1.getText().toString(), et2.getText().toString(), loginListener);
                Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
                break;

                //break;
            case R.id.button2:
                Intent intent1=new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent1);
                break;

        }
    }
}
